package com.example.fp.zlz.util;

import static java.lang.Math.min;

public class PageUtil {
     public static class Page {
         public int page;
         public int maxPage;
         public int currLoc;
         public int currMaxPage;

         public Page(int page, int maxPage, int currLoc, int currMaxPage) {
             this.page=page;
             this.maxPage=maxPage;
             this.currLoc=currLoc;
             this.currMaxPage=currMaxPage;
         }
     }

    public static Page getPage(int pageD, int count, int pageSize){
        int page = pageD;
        if (page == 0) {
            page = 1;
        }
        int maxPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
        if (page > maxPage) {
            page = maxPage;
        }

        int currLoc = (page - 1) * pageSize;

        int currMaxPage = min(page + pageSize, maxPage);

        return new Page(page, maxPage, currLoc, currMaxPage);
    }
}
